package com.example.droolstool.controller;

import com.example.droolstool.module.TaxiFare;
import com.example.droolstool.module.TaxiRide;
import com.example.droolstool.service.TaxiFareCalculateService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * 计程车计费
 * @Author 赵云龙
 * @Date 2020/6/6
 * @Description TODO
 */

@RestController
@RequestMapping("taxi")
public class TaxiController {


    @Resource
    TaxiFareCalculateService taxiFareCalculateService;

    @GetMapping("cal")
    public ResponseEntity<Object> calTaxiFare(TaxiRide taxiRide) {
        if (taxiRide.getNightSurcharge() == null){
            taxiRide.setNightSurcharge(false);
        }

        if (taxiRide.getDistanceInMile() == null){
            taxiRide.setDistanceInMile(new BigDecimal(9));
        }
        TaxiFare fare = new TaxiFare();
        BigDecimal totalCharge = taxiFareCalculateService.calculatorFare(taxiRide, fare);
        String totalChargeStr = totalCharge.setScale(1, BigDecimal.ROUND_UP).stripTrailingZeros().toPlainString();
        return ResponseEntity.ok(totalChargeStr);

    }

}
